/*
 * 
 * 
 * 
 */
package org.jjliu.example.action;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.util.WebUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Controller - 会员中心
 * 
 * 
 * 
 */
@Controller
public class MemberController extends BaseController {

	/** 最新订单数 */
	private static final int NEW_ORDER_COUNT = 6;

	enum MyType{
		TYPE1,TYPE2,TYPE3
	}
	/**
	 * 首页
	 */
	@ResponseBody
	@RequestMapping(value = "/test" )
	public Map<String, Object> test(Date now,MyType type) {
		System.out.println(type);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("fe", "fefe");
		map.put("now", type.ordinal());
		return map;
	}
	/**
	 * 首页
	 */
	@RequestMapping(value = "/index" )
	public String index(HttpSession httpsession) {
		Subject subject = SecurityUtils.getSubject();
		Session session =  subject.getSession();
		session.setAttribute("test1", "test1");
		String hst1 = (String) httpsession.getAttribute("test1");
		String username = (String) subject.getPrincipal();
		return "index";
	}

	@RequestMapping(value = "/login" )
	public String login() {
		return "login";
	}

	@RequestMapping(value = "/login_submit" )
	public String login_submit(String username,String passwd,HttpServletRequest request) {
		UsernamePasswordToken token = new UsernamePasswordToken(username, passwd);
		Subject subject = SecurityUtils.getSubject();
		subject.login(token);
		String url = WebUtils.getRequestUri(request);
		return "redirect:"+url;
	}

}